<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection"
	content="telephone=no,email=no,date=no,address=no">
<title></title>
<link rel="stylesheet" type="text/css" href="../css/aui.css" />
<link rel="stylesheet" type="text/css"
	href="../css/aui-pull-refresh.css" />
<style>
			.aui-content-padded {
				padding: 0.75 rem;
				background-color: #ffffff;
				margin-top: 0.75 rem;
			}
			.aui-list-item-label {
				font-size: 14px;
			}
			.aui-list-item-inner .input-class {
				font-size: 13px;
			}
			.aui-list-item-input {
				font-size: 13px;
			}
</style>
</head>
<body>
	<header class="aui-bar aui-bar-nav aui-bar-warning" id="aui-header">
	<a class="aui-pull-left" onclick="window.history.back(-1);"> <span
		class="aui-iconfont aui-icon-left"></span>
	</a>
	<div class="aui-title">修改密码</div>
	<a class="aui-pull-right"> </a> </header>
	
	
		<section class="aui-content" >
			<form id="myFrom">
				<ul class="aui-list aui-list-in aui-margin-b-15">
					<li class="aui-list-item aui-list-item-middle" onclick="loadAvatar()" >
						<div class="aui-list-item-label">
							头像:
						</div>
						
						<label for="hotelImgFile">
						<div class="aui-list-item-media" style="width: 3.5rem;">
							<img src="../img/bing.png"
								class="aui-img-round aui-list-img-sm" id="picture1"> 
								 	<input type="hidden" name="picture" id="picture" />
						</div>
						<input type="file" id="hotelImgFile" name="hotelImgFile" style="display: none" />
						</label>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-label">
							姓名:
						</div>
						<div class="aui-list-item-inner">
							<input type="text" class="input-class" placeholder="请输入姓名" id="name" name="name">
							<input type="hidden"  id="employeeId" name="employeeId">
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-label ">
							性别:
						</div>
						<div class="aui-list-item-inner" >
							<select class="input-class" id="sex" name="sex">
								<option value="男" >男</option>
								<option value="女">女</option>
							</select>
							<i class="aui-iconfont aui-icon-down" style="position:absolute;top: 10px;right: 10px;color: #D2D2D2;" ></i>
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-label">
							出生日期:
						</div>
						<div class="aui-list-item-inner">
							<input type="date" class="input-class" placeholder="出生日期" id="birthday" name="birthday">
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-label">
							职业:
						</div>
						<div class="aui-list-item-inner aui-list-item-input" id="position" ></div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-label">
							座机号码:
						</div>
						<div class="aui-list-item-inner">
							<input type="text" class="input-class" placeholder="请输入座机号码" id="phoneNumber" name="phoneNumber">
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-label">
							传真号码:
						</div>
						<div class="aui-list-item-inner aui-list-item-input" placeholder="请输入传真号码" id="deptName"></div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-label">
							其他联系方式:
						</div>
						<div class="aui-list-item-inner">
							<input type="text" class="input-class" placeholder="请输入邮箱" id="email" name="email">
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-label">
							联系地址:
						</div>
						<div class="aui-list-item-inner">
							<input type="text" class="input-class" placeholder="请输入地址" id="address" name="address">
						</div>
					</li>
				</ul>
				<div class="aui-btn aui-btn-primary aui-btn-block" onclick="submitCustomer()" style="margin: 0 auto;width: 95%;">
					提交
				</div>
			</form>
		</section>
		<div class="aui-toast"  style="display:none;" id="loading">
			<div class="spinner aui-toast-content">
				<div class="spinner-container container1">
					<div class="circle1"></div>
					<div class="circle2"></div>
					<div class="circle3"></div>
					<div class="circle4"></div>
				</div>
				<div class="spinner-container container2">
					<div class="circle1"></div>
					<div class="circle2"></div>
					<div class="circle3"></div>
					<div class="circle4"></div>
				</div>
				<div class="spinner-container container3">
					<div class="circle1"></div>
					<div class="circle2"></div>
					<div class="circle3"></div>
					<div class="circle4"></div>
				</div>
			</div>
		</div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery.qrcode.min.js"></script>
<script type="text/javascript" src="../js/aui-dialog.js" ></script>
<script type="text/javascript" src="../js/common.js"></script>


<script type="text/javascript">
	var dialog = new auiDialog({});
	//传入id
	var id = "${param.id}";
	
	//初始方法
	$(function(){
		 	getPage();
			//选择头像之后的事件 
			$("#hotelImgFile").change(function(){
				var file=$("#hotelImgFile");
				var suffix=file.val().substring(file.val().lastIndexOf(".")+1,file.val().length);
				var picture=file.val().substring(file.val().lastIndexOf("\\")+1,file.val().length);
				var imageSize=file[0].files[0].size/1024;//kb
				//JPG,JPEG,PNG,BMP,GIF格式
				if(suffix!="jpg"&&suffix!="jpeg"&&suffix!="png"&&suffix!="bmp"&&suffix!="gif"){
					file.val("");//清空
					sweetAlert("提示", "仅支持10M以下JPG,JPEG,PNG,BMP,GIF格式图片!", "error");
				}else if(imageSize>1024*5){  //仅支持5M内的图片
					file.val("");//清空
					sweetAlert("提示", "图片文件的大小不能超过5M!", "error");
				}else{
					$("#picture").val(file.val());
				}		
			});
		});

	function getPage() {
		$.ajax({
					url : '${pageContext.request.contextPath}/appcrm/cardDetail.do',
					type : "POST",
					dataType : "json",
					success : function(data) {
						if (data.code == "0") {
							if (data.emp != "undefined") {
								$("#employeeId").val(data.emp.employeeId);
								$("#sex").html(data.emp.sex);
								$("#birthday").html(toDate(data.emp.birthday));
								$("#position").html(data.emp.position);
								$("#deptName").html(data.emp.dept.deptName);
								if (data.emp.email != "") {
									$("#email").val(data.emp.email);
									$("#email").attr("placeholder", "");
								}
								if (data.emp.address != "") {
									$("#address").val(data.emp.address);
									$("#address").attr("placeholder", "");
								}
								if (data.emp.phoneNumber != "") {
									$("#phoneNumber").val(data.emp.phoneNumber);
									$("#phoneNumber").attr("placeholder", "");
								}
								if (data.emp.name != "") {
									$("#name").val(data.emp.name);
									$("#name").attr("placeholder", "");
								}
								if (data.emp.picture != "" && data.emp.picture != null) {
									$("#picture1").attr("src", '${pageContext.request.contextPath}/'+ data.emp.picture);
									$("#picture").val(data.emp.picture);
								}
							}
						}
					}
				});
	}
	


	function submitCustomer() {
		var name = $("#name").val().trim();
		var phoneNumber = $("#phoneNumber").val().trim();
		var email = $("#email").val().trim();
		var address = $("#address").val().trim();

		if (name == "") {
			showMsg("请填写姓名!");
			return false;
		}
		if (phoneNumber == "") {
			showMsg("请填写手机号码!");
			return false;
		}
		if (email == "") {
			showMsg("请填写邮箱!");
			return false;
		}
		var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (reg.test(email)) {
				jQuery("#email").val(email);
			} else {
				jQuery("#email").val("");
				showMsg("您输入的邮箱格式有误!");
				return false;
			}
 
		var formData = new FormData  ($("form")[0]);
		
		$.ajax({
			url : '${pageContext.request.contextPath}/appcrm/modify.do',
			type : "POST",
			data : formData,
		     cache:false,
		     contentType: false,
		     processData: false,
			success : function(data) {
				if (data.code == 0) {
					showMsg("提交成功");
				} else {
					showMsg("提交失败");
				}
				setTimeout(function() { 
				window.location.href=window.location.href;
				window.location.reload;
				}, 1000);
				

			}
			
		});
	}

	function toDate(data) {
		var date = new Date(data);
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		m = m < 10 ? '0' + m : m;
		var d = date.getDate();
		d = d < 10 ? ('0' + d) : d;
		return y + '-' + m + '-' + d;
	}
	/**
	 *转换金钱100,000.00 
	 */
	function formatCurrency(num) {
		if (num != null && num != "") {
			num = num.toString().replace(/\$|\,/g, '');
			if (isNaN(num))
				num = "0";
			sign = (num == (num = Math.abs(num)));
			num = Math.floor(num * 100 + 0.50000000001);
			cents = num % 100;
			num = Math.floor(num / 100).toString();
			if (cents < 10)
				cents = "0" + cents;
			for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
				num = num.substring(0, num.length - (4 * i + 3)) + ','
						+ num.substring(num.length - (4 * i + 3));
			return (((sign) ? '' : '-') + num + '.' + cents);
		}
	}



</script>
</html>